1 : <?php
2 : /*--------------------------------------------------------------------------+
3 : This file is part of eStudy.
4 : suchmaschine/classes/class.indexer.inc.php
5 : - Modulgruppe: Suche
6 : - Beschreibung: In dieser Datei wird die Klasse IndexerStrategy implementiert.
7 : - Version: 0.1 01/08/08
8 : - Autor(en): Jörg Rieger
9 : +---------------------------------------------------------------------------+
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or any later version.
14 : +---------------------------------------------------------------------------+
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 : You should have received a copy of the GNU General Public License
20 : along with this program; if not, write to the Free Software
21 : Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 : +--------------------------------------------------------------------------*/
23 : /**
24 : * Path to Root falls nicht gesetzt
25 : */
26 : if (!defined('PATH_TO_ROOT')) {
27 : define("PATH_TO_ROOT", "../../");
28 :
29 : require_once('class.iindexer.inc.php');
30 : require_once('class.indexer.inc.php');
31 : }
32 :
33 : /**
34 : * IndexerStrategy Klasse setzt das Strategy Pattern um.
35 : *
36 : * @package eStudy.Suchmaschine
37 : * @version 0.1 01/08/08
38 : * @author Jörg Rieger
39 : */
40 :
41 : class IndexerStrategy {
42 : /**
43 : * Enthält das Strategy Objekt
44 : *
45 : * @var object
46 : * @access private
47 : */
48 : private $strategy;
49 :
50 : /**
51 : * Enthält alle von den Plugins Unterstützten Datei-Typen/-Formate
52 : *
53 : * @var array
54 : * @access private
55 : */
56 : private $formats = array();
57 :
58 : /**
59 : * Kontruktor
60 : *
61 : * @access public
62 : */
63 : public function IndexerStrategy() {
64 0 : $this->formats = $this->retrieveFileTypes();
65 0 : }
66 :
67 : /**
68 : * Instatiiert das Plugin
69 : *
70 : * @access public
71 : * @param Name des Plugins
72 : */
73 : public function usePlugin( $name ) {
74 0 : $constName = 'Plugin' . $name;
75 :
76 0 : if( $this->pluginExists($constName) )
77 0 : $this->strategy = new $constName();
78 : else
79 0 : $this->strategy = new PluginVoid();
80 0 : }
81 :
82 : /**
83 : * Öffnen der Datei
84 : *
85 : * @access public
86 : */
87 : public function open( $fileName ) {
88 0 : return $this->strategy->open( $fileName );
89 : }
90 :
91 : /**
92 : * Lesen der Datei
93 : *
94 : * @access public
95 : */
96 : // public function read() {
97 : // return $this->strategy->read();
98 : // }
99 :
100 : /**
101 : * Inhalt zurückgeben
102 : *
103 : * @access public
104 : * @return string
105 : */
106 : public function getContent() {
107 0 : return $this->strategy->getContent();
108 : }
109 :
110 : /**
111 : * Schliessen der Datei
112 : *
113 : * @access public
114 : */
115 : public function close() {
116 0 : return $this->strategy->close();
117 : }
118 :
119 : /**
120 : * Temporäre Dateien entfernen
121 : *
122 : * @access public
123 : */
124 : public function cleanup() {
125 0 : return $this->strategy->cleanup();
126 : }
127 :
128 : /**
129 : * Gibt den Namen des verwenderten Plugins zurück
130 : *
131 : * @access public
132 : */
133 : public function getPluginName() {
134 0 : return '[Plugin' . $this->strategy->name . '] ';
135 : }
136 :
137 : /**
138 : * Gibt die von den Plugins Unterstützten Datei-Typen/-Formate zurück
139 : *
140 : * @access public
141 : * @return array
142 : */
143 : public function getFileTypes() {
144 0 : return $this->formats;
145 : }
146 :
147 : /**
148 : * Gibt die von den Plugins Unterstützten Datei-Typen/-Formate zurück
149 : *
150 : * @access public
151 : * @return array
152 : */
153 : public function retrieveFileTypes() {
154 0 : $array = array();
155 :
156 0 : foreach (glob(PATH_TO_ROOT . 'suchmaschine/classes/class.plugin*.inc.php') as $filename) {
157 0 : require_once($filename);
158 :
159 0 : $className = substr($filename, strpos($filename, 'plugin'), strlen($filename));
160 0 : $className = substr($className, 0, strpos($className, '.'));
161 :
162 0 : $obj = new $className();
163 0 : $newArray = array();
164 :
165 0 : foreach($obj->fileExt as $key => $val) {
166 0 : $newArray[$val] = strtolower($obj->name);
167 0 : }
168 :
169 0 : $array = array_merge($array, $newArray);
170 0 : }
171 :
172 0 : return $array;
173 : }
174 :
175 : /**
176 : * Prüft ob die entsprechende Plugin Klasse existiert
177 : *
178 : * @access public
179 : * @return boolean
180 : */
181 : protected function pluginExists( $name ) {
182 0 : if( file_exists(PATH_TO_ROOT . 'suchmaschine/classes/class.' . strtolower($name) . '.inc.php') )
183 0 : return true;
184 : else
185 0 : return false;
186 : }
187 :
188 :
189 : }
|